<?php if(!defined('BASEPATH')) exit('No direct script allowed');

class mdl_msignup extends CI_Model{
	
	function __construct()
	{
		parent::__construct();
	}
	
	function get_item($lim=0, $num=0,$arr_where='')
	{
		$this->db->flush_cache();
		$this->db->select('*');
		$this->db->from('tmusers');
		if ($arr_where!=''){
			$this->db->where($arr_where);
		}
		$this->db->order_by("channelid", "asc");
		if ($lim!=0){
			$this->db->limit($lim,$num);
		}
		return $this->db->get();
	}
	
	function get_countitem($arr_where=''){
		$this->db->flush_cache();
		$this->db->select('*');
		$this->db->from('tusers');
		if ($arr_where!=''){
			$this->db->where($arr_where);
		}
		return  $this->db->count_all_results();
	}
	
	function getItemById($id)
	{
		$this->db->flush_cache();
		$this->db->where('userid', $id);
		return $this->db->get('users');
		
	}

	function insert($data)
	{
	
	
		$this->db->flush_cache();
		$this->db->set('firstname', $data['firstname']); 
		$this->db->set('lastname', $data['lastname']); 
		$this->db->set('username', $data['username']); 
		$this->db->set('password', $data['password']); 
		$this->db->set('company', $data['company']); 
		$this->db->set('designation', $data['designation']); 
		$this->db->set('address', $data['address']); 
		$this->db->set('city', $data['city']); 
		$this->db->set('country', $data['country']); 
		$this->db->set('countrycode', $data['countrycode']); 
		$this->db->set('phone', $data['phone']); 
		$this->db->set('ip', $data['ip']); 
		$this->db->set('device', $data['device']); 
		$this->db->set('os', $data['os']); 
		$this->db->set('location', $data['location']); 
		
		
		$this->db->set('deviceid', $data['deviceid']); 
		
		$this->db->set('signupdate', $data['signupdate']); 
		$this->db->set('langid', $data['langid']); 
		$this->db->set('priv', $data['priv']); 

	$this->db->set('verificationtoken', $data['verificationtoken']); 
		//$this->db->set('lang', $data['lang']); 

		
        $result = $this->db->insert('tmusers');
		
		//$result=$this->db->insert('users', $data);
		if($result) {
			return TRUE;
		}else {
			return FALSE;
		}
	} 
	
	function updateappsid($username, $appsid)
	{
		$this->db->flush_cache();
	//	$this->db->set('userid', $data['userid']); 
//$this->db->set('username', $data['username']); 
$this->db->set('appsid', $appsid); 
//$this->db->set('level_id', $data['level_id']); 

		$this->db->where('username', $username);
		//$result=$this->db->update('tusers', $data);
		$result=$this->db->update('tusers');
		
		if($result) {
			return TRUE;
		}else {
			return FALSE;
		}
	} 
	
	function updateip($username, $data)
	{
		$this->db->flush_cache();
		$this->db->set('ip', $data['ip']); 
		$this->db->set('device', $data['device']); 
		$this->db->set('os', $data['os']); 
		$this->db->set('location', $data['location']); 

		$this->db->where('username', $username);
		//$result=$this->db->update('tusers', $data);
		$result=$this->db->update('tusers');
		
		if($result) {
			return TRUE;
		}else {
			return FALSE;
		}
	} 
/*	
	function delete($id)
	{
		
		$this->db->flush_cache();
		$this->db->where('userid', $id);
		$result = $this->db->delete('users');
		
		if($result) {
			return TRUE;
		}else {
			return FALSE;
		}
		
	}
	*/
}
